package com.leetcode.algorithm.y22.m07;

/**
 * 383. 赎金信
 * 
 * https://leetcode.cn/problems/ransom-note/
 * 
 * @author jie.deng
 *
 */
class Question0383Solution01 {
	
	public boolean canConstruct(String ransomNote, String magazine) {
		int[] cntArr = new int[26];
		for (int i = 0; i < magazine.length(); i++) {
			cntArr[magazine.charAt(i) - 'a']++;
		}
		for (int i = 0; i < ransomNote.length(); i++) {
			int idx = ransomNote.charAt(i) - 'a';
			if (cntArr[idx] == 0) {
				return false;
			}
			cntArr[idx]--;
		}
		return true;
	}
    
}